<?php

require_once __DIR__ . '/../inc/App.php';

$app = new App("Recherche");
$db = $app->getDb();

$recherche = $_POST['recherche'];
$results = search($db, $recherche);
if (!$results) {
    echo "<div class='alert alert-danger'>Aucun document ne correspond à votre recherche<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span></button></div>";
} else {
    $s = count($results) > 1 ? "s" : "";
    ?>
    <div class="alert alert-success">
        <strong><?php echo count($results); ?></strong>
        résultat<?php echo $s; ?> trouvé<?php echo $s; ?>
    </div>
    <?php
    foreach ($results as $indexClass) {
        $document   = $indexClass->getDocument();
        $image      = $document->getIcone() ? $document->getIcone() : 'http://arppinfoservices.com/images/css/photo_indisponible.jpg';
        ?>
        <div class="row">
            <div class="col-md-2">
                <img class="img-responsive" alt="<?php echo $document->getTitre(); ?>" src="<?php echo $image; ?>"  style="max-height:150px;margin-left:auto;margin-right:auto;"/>
            </div>
            <div class="col-md-10">
                <span class="label label-primary"><?php echo $indexClass->getRobertson(); ?></span>
                <a href="data/<?php echo $document->getPath(); ?>">
                    <h3><?php echo $document->getTitre(); ?></h3>
                </a>
                
                <p><?php echo $document->getDescription(); ?></p>
            </div>
        </div>
        <br />
        <?php
    }
}
